define(["Zepto", 
        "underscore", 
        "Backbone", 
        "Handlebars",  
        "text!templates/pagep/student.html",
        "collections/corsostudentecollection",
        "views/student/coursesview",
        "views/common/menuview"
], function($, _, Backbone, Handlebars, template, CorsostudenteCollection, CoursesView, MenuView) {
	
   
	  var StudentPageP = Backbone.View.extend({
		  
	        template: Handlebars.compile(template),

	        render: function(eventName) {
	        	
	        	this.$el.html(this.template(this.model.toJSON()));
	        	
	        	// menu top
	        	this.menutop = new MenuView({
	               	el : $('#menu', this.el),
	    			model : this.model
				});
	            this.menutop.render();
	        	
	            this.corsostudenteCollection = new CorsostudenteCollection();
				this.corsostudenteCollection.fetch({
					query : {
						//terminato: false,
						notifica: true,
						utente: {"__type":"Pointer","className":"_User","objectId":this.model.get('objectId')}
	               		},
	               	 include : 'corso',          //Include un oggetto di tipo Puntatore
	               	success: function(data) {
	                	this.courses = new CoursesView({	    				
							el : $('#corsi ul', this.el),
							model : data
	    				});
	                	this.courses.render();
	                	// if(data.length < 1){
	                	//     $('#label1').text("Nessun corso seguito");
	                	// }
					}});
				
					
				
	            return this;
	        },

	        events: {
	        	
	            'touchstart .button': 'over',
	            'touchend .button': 'left',
	            'touchcancel .button': 'left',
	            'touchstart button': 'over',
	            'touchend button': 'left',
	            'touchcancel button': 'left',
	            'touchstart .ac-container article.selectable ul li': 'over',
	            'touchend .ac-container article.selectable ul li': 'left',
	            'touchcancel .ac-container article.selectable ul li': 'left'
	        },


	        over: function(event) {
	            $(event.currentTarget).addClass('fake-active');
	        },

	        left: function(event) {
	            $(event.currentTarget).removeClass('fake-active');
	        }

	});

    return StudentPageP;

});

